package ingredientsClient;

import java.util.Vector;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPFactory;

public class SoapMethod {
    private String name; // a String giving the local name for the new element
    private String prefix; // a String giving the namespace prefix for the new element
    private String uri; // a String giving the URI of the namespace to which the new element belongs
    
    private Vector<SoapParameter> parameters;
    
    public SoapMethod( String name, String prefix, String uri ) {
        this.setName(name);
        this.setPrefix(prefix);
        this.setUri(uri);
        
        parameters = new Vector<SoapParameter>();
    }
    
    public SOAPElement getElement()  throws javax.xml.soap.SOAPException
    {
        SOAPElement se;
        
        SOAPFactory sf = SOAPFactory.newInstance();
        se = sf.createElement(name,prefix,uri);

        for( int i = 0 ; i < parameters.size(); i++ )
        {
            SoapParameter sp = parameters.get( i );
            SOAPElement p = se.addChildElement(sp.getName());
            p.addTextNode(sp.getValue());
        }
        
        return se;
    }
    
    public void addParameter( SoapParameter parameter )
    {
        parameters.add(parameter);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPrefix() {
        return prefix;
    }

    public void setPrefix(String prefix) {
        this.prefix = prefix;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }
}
